/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package babydisco.Math;

import java.util.ArrayList;

/**
 * Noise filtering class based on what is in
 * Signal Analysis for ECG Interpretation
 * @author florian
 */
public class NoiseFiltering {

    private ArrayList<Double> input, weigthDiffFiltered;
    private double inputFreq;
    private int filterSize = 5; // how far thefilter goes, so from -size till + size
                                //currently this means that the filter filters out
                                //everything below 100HZ, given that heart rates are below
                                //4HZ this seems good for the moment
    public NoiseFiltering(ArrayList<Double>  input, double inputFreq){
        this.input = input;
        weigthDiffFiltered = new ArrayList<Double>();
        this.inputFreq = inputFreq;
        weigthedDifferentiationFilter();
    }

    /**
     * weigthed differentiation filter
     * Unfortunatly the slow one cuz I can't read what the formula
     * says for the lineair one
     * (2*m+1)*duration of one sample = length of filtered samples
     * 1/length = freq
     */
    private void weigthedDifferentiationFilter(){
        for(int i = filterSize;i< input.size()-filterSize;i++){
            double filtered =  0;
            for(int j = -filterSize/2; j < filterSize;j++){
                filtered += j*input.get(i+j);
            }
            weigthDiffFiltered.add(filtered);
        }
    }



    public ArrayList<Double> getWeigthDiffFiltered(){
        return weigthDiffFiltered;
    }
    public double getFilteredFreq(){
        return 1/(filterSize*2*(1/inputFreq));
    }
}
